//
//  newSideBarViewController.m
//  WisdomZhuHai
//
//  Created by Ryan on 15-1-14.
//  Copyright (c) 2015年 wyd. All rights reserved.
//

#import "newSideBarViewController.h"
#import "Common.h"
//#import "RootViewController.h"
#import "TransforController.h"
#import "GoodDetailViewController.h"
#import "MobClick.h"

static const CGFloat TITLE_CELL_HEIGHT = 38;
static const CGFloat WHO_CELL_HEIGHT = 118;
static const CGFloat GO_TO_WHERE = 185;
static const CGFloat HOW_FAR_CELL_HEIGHT = 90;
static const CGFloat KM_SELECT_CELL_HEIGHT = 70;

@interface newSideBarViewController ()

@property(nonatomic, assign)UIView* whereView;
@property(nonatomic, assign)UISlider* slider;
@property(nonatomic, assign)UITableViewCell* cell;

@property(nonatomic, assign)BOOL whereState;
@property(nonatomic, strong)NSMutableArray* typesSelected;
@property(nonatomic, strong)NSMutableArray* tagsSelected;
@property(nonatomic, strong)NSMutableArray* areasSelected;
@property(nonatomic, strong)NSString* distance;
@property(nonatomic, strong)NSString* gps;

@end

@implementation newSideBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 19, self.view.bounds.size.width, self.view.bounds.size.height)];
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.scrollEnabled = YES;
    _tableView.dataSource = self;
    _tableView.delegate = self;
    self.tagsSelected = [[NSMutableArray alloc] init];
    self.typesSelected = [[NSMutableArray alloc] init];
    self.areasSelected = [[NSMutableArray alloc] init];
    UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 19)];
    titleView.backgroundColor = [Common colorWithRGB:0x18aaf2];
    [self.view addSubview:titleView];
    [self.view addSubview:_tableView];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - cell

-(void)whoCellSetup:(UITableViewCell*)cell
{
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 10, 100, 20)];
    titleLabel.font = [UIFont fontWithName:@"Arial" size:15.0];
    titleLabel.textColor = [Common colorWithRGB:0x4c4c4c];
    titleLabel.text = @"去哪儿";
    [cell.contentView addSubview:titleLabel];
    
    NSArray *imgArray = [NSArray arrayWithObjects:@"siftSideBar/jingdian", @"siftSideBar/meisi", @"siftSideBar/dianying", @"siftSideBar/gouwu", @"siftSideBar/jiudian", @"siftSideBar/wenhuayishu", @"siftSideBar/xiangcun", @"siftSideBar/wenquan", nil];
    NSArray *imgName = [NSArray arrayWithObjects:@"景点", @"美食", @"电影", @"购物", @"酒店", @"文化", @"乡村", @"温泉", nil];
    NSArray *typeId = [NSArray arrayWithObjects:@"6", @"9", @"电影", @"11", @"5", @"文化", @"乡村", @"温泉", nil];
    int imgX = 0;
    int imgY = 36;
    for (int i = 0; i < imgArray.count; i++) {
        if (i == 4) {
            imgY = imgY * 3;
            imgX = 0;
        }
        UIView *whoView = [[UIView alloc] initWithFrame:CGRectMake(imgX + 30, imgY, 50, 70)];
        whoView.backgroundColor = [UIColor clearColor];
        UIImageView *whoImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
        whoImg.image = [UIImage imageNamed:imgArray[i]];
        [whoView addSubview:whoImg];
        UILabel *imgNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, 50, 20)];
        imgNameLabel.font = [UIFont fontWithName:@"Arial" size:12.0];
        imgNameLabel.textColor = [Common colorWithRGB:0x4c4c4c];
        imgNameLabel.textAlignment = UITextAlignmentCenter;
        imgNameLabel.text = imgName[i];
        [whoImg setAccessibilityValue:imgArray[i]];
        [whoImg setAccessibilityIdentifier:typeId[i]];
        UITapGestureRecognizer *onTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(chooseWho:)];
        whoImg.tag = 10001;
        [whoView addSubview:imgNameLabel];
        [whoView addGestureRecognizer:onTap];
        [cell.contentView addSubview:whoView];
        imgX += 70;
    }
    
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(15, GO_TO_WHERE - 0.5, self.view.bounds.size.width - 30, 0.5)];
    lineView.backgroundColor = [Common colorWithRGB:0xb2b2b2];
    [cell.contentView addSubview:titleLabel];
    [cell.contentView addSubview:lineView];
}

-(void)withWhoCellSetup:(UITableViewCell*)cell
{
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 10, 100, 20)];
    titleLabel.font = [UIFont fontWithName:@"Arial" size:15.0];
    titleLabel.textColor = [Common colorWithRGB:0x4c4c4c];
    titleLabel.text = @"和谁玩";
    [cell.contentView addSubview:titleLabel];
    
    NSArray *imgArray = [NSArray arrayWithObjects:@"siftSideBar/icon_sidebar_brother", @"siftSideBar/icon_sidebar_lovers", @"siftSideBar/icon_sidebar_family", @"siftSideBar/icon_sidebar_group", nil];
    NSArray *imgName = [NSArray arrayWithObjects:@"好友", @"情侣", @"家庭", @"团体", nil];
    int imgX = 0;
    for (int i = 0; i < imgArray.count; i++) {
        UIView *whoView = [[UIView alloc] initWithFrame:CGRectMake(imgX + 30, 36, 50, 70)];
        whoView.backgroundColor = [UIColor clearColor];
        UIImageView *whoImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
        whoImg.image = [UIImage imageNamed:imgArray[i]];
        [whoView addSubview:whoImg];
        UILabel *imgNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, 50, 20)];
        imgNameLabel.font = [UIFont fontWithName:@"Arial" size:12.0];
        imgNameLabel.textColor = [Common colorWithRGB:0x4c4c4c];
        imgNameLabel.textAlignment = UITextAlignmentCenter;
        imgNameLabel.text = imgName[i];
        [whoImg setAccessibilityValue:imgArray[i]];
        [whoImg setAccessibilityIdentifier:imgName[i]];
        UITapGestureRecognizer *onTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(chooseWithWho:)];
        whoImg.tag = 20001;
        [whoView addSubview:imgNameLabel];
        [whoView addGestureRecognizer:onTap];
        [cell.contentView addSubview:whoView];
        imgX += 70;
    }
    
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(15, WHO_CELL_HEIGHT - 0.5, self.view.bounds.size.width - 30, 0.5)];
    lineView.backgroundColor = [Common colorWithRGB:0xb2b2b2];
    [cell.contentView addSubview:titleLabel];
    [cell.contentView addSubview:lineView];
}

-(void)howFarCellSetup:(UITableViewCell*)cell
{
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 10, 100, 20)];
    titleLabel.font = [UIFont fontWithName:@"Arial" size:15.0];
    titleLabel.textColor = [Common colorWithRGB:0x4c4c4c];
    titleLabel.text = @"去多远";
    [cell.contentView addSubview:titleLabel];
    
    NSArray *area = [NSArray arrayWithObjects:@"香洲区", @"斗门区", @"金湾区", @"万山区", @"横琴新区", @"周边城市", nil];
    int imgX = 0;
    int imgY = 35;
    for (int i = 0; i < area.count; i++) {
        if (i == 4) {
            imgX = 0;
            imgY = 60;
        }
        UIView *whereView = [[UIView alloc] initWithFrame:CGRectMake(imgX + 40, imgY, 54, 18)];
        whereView.backgroundColor = [UIColor clearColor];
        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, whereView.frame.size.width, 18)];
        [imgView setAccessibilityValue:@"siftSideBar/choose_in"];
        imgView.image = [UIImage imageNamed:@"siftSideBar/choose_in"];
        [whereView addSubview:imgView];
        UILabel *imgNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, whereView.frame.size.width, 18)];
        imgNameLabel.font = [UIFont fontWithName:@"Arial" size:12.0];
        imgNameLabel.textColor = [Common colorWithRGB:0x4c4c4c];
        imgNameLabel.textAlignment = UITextAlignmentCenter;
        imgNameLabel.text = area[i];
        UITapGestureRecognizer *onTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(chooseWhere:)];
        imgView.tag = 30001;
        imgView.accessibilityIdentifier = area[i];
        imgNameLabel.tag = 30002;
        [whereView addSubview:imgNameLabel];
        imgNameLabel.userInteractionEnabled = YES;
        [whereView addGestureRecognizer:onTap];
        [cell.contentView addSubview:whereView];
        imgX += 60;
    }
    
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(15, HOW_FAR_CELL_HEIGHT - 0.5, self.view.bounds.size.width - 30, 0.5)];
    lineView.backgroundColor = [Common colorWithRGB:0xb2b2b2];
    [cell.contentView addSubview:titleLabel];
    [cell.contentView addSubview:lineView];
}

-(void)slideCellSetup:(UITableViewCell*)cell
{
    UISlider* slider = [[UISlider alloc] initWithFrame:CGRectMake(40, 30, 240, 5)];
    self.slider = slider;
    //设置未滑动位置背景图片
    [slider setMinimumTrackImage:[UIImage imageNamed:@"siftSideBar/blueLine"] forState:UIControlStateNormal];
    //设置已滑动位置背景图
    [slider setMaximumTrackImage:[UIImage imageNamed:@"siftSideBar/grayLine"] forState:UIControlStateNormal];
    //设置滑块图标图片
    [slider setThumbImage:[UIImage imageNamed:@"siftSideBar/dot"] forState:UIControlStateNormal];
    //设置点击滑块状态图标
    //[slider setThumbImage:[UIImage imageNamed:@"main_slider_btn.png"] forState:UIControlStateHighlighted];
    //设置起始位置
    slider.value=0;
    //设置最小数
    slider.minimumValue=20;
    //设置最大数
    slider.maximumValue=252;
    //设置背景颜色
    slider.backgroundColor = [UIColor clearColor];
    //设置委托事件
//    [slider addTarget:self action:@selector(sliderMove:) forControlEvents:UIControlEventValueChanged];
    [cell.contentView addSubview:slider];
    NSArray *nameArray = [NSArray arrayWithObjects:@"全部", @"500米", @"1000米", @"2000米", @"5000米", nil];
    CGFloat dotX = 20.0;
    for (int i = 0; i < 5; i++){
        UIView *dotView = [[UIView alloc] initWithFrame:CGRectMake(dotX, 27, 40, 40)];
        dotView.backgroundColor = [UIColor clearColor];
        UIImageView *dotImg = [[UIImageView alloc] initWithFrame:CGRectMake(20, 0, 10, 10)];
        dotImg.image = [UIImage imageNamed:@"siftSideBar/dot_grey"];
        if (i == 0) {
            dotImg.image = [UIImage imageNamed:@"siftSideBar/dot_blue"];
        }
        dotImg.tag = 40001;
        [dotView addSubview:dotImg];
        UILabel *dotName = [[UILabel alloc] initWithFrame:CGRectMake(0, 12, dotView.bounds.size.width, 20)];
        dotName.font = [UIFont fontWithName:@"Arial" size:10.0];
        dotName.textColor = [Common colorWithRGB:0x4c4c4c];
        dotName.text = nameArray[i];
        dotName.textAlignment = UITextAlignmentCenter;
        dotName.tag = 40002;
        UITapGestureRecognizer *onTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(chooseDistance:)];
        NSString *distance = nameArray[i];
        dotView.accessibilityIdentifier = [distance componentsSeparatedByString:@"米"][0];
        [dotView addSubview:dotName];
        [dotView addGestureRecognizer:onTap];
        dotView.tag = 40000 + dotView.frame.origin.x;
        [cell.contentView addSubview: dotView];
        dotX += 58;
    }
    self.cell = cell;
}

-(void)buttonCellSetup:(UITableViewCell*)cell
{
    CGSize btnSize = {80, 30};
    CGSize labelSize = {80, 30};
    UIImageView *deleteBtnImg = [[UIImageView alloc] initWithFrame:CGRectMake(60, 5, btnSize.width, btnSize.height)];
    deleteBtnImg.image = [UIImage imageNamed:@"siftSideBar/btn_gray"];
    UILabel *deleteLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, labelSize.width, labelSize.height)];
    deleteLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:15.0];
    deleteLabel.textColor = [Common colorWithRGB:0x666666];
    deleteLabel.text = @"清除条件";
    deleteLabel.textAlignment = UITextAlignmentCenter;
    [deleteBtnImg addSubview:deleteLabel];
    deleteBtnImg.userInteractionEnabled = YES;
    UITapGestureRecognizer *onTapDeleteBtn = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(deleteBtn:)];
    [deleteBtnImg addGestureRecognizer:onTapDeleteBtn];
    
    UIImageView *finishBtnImg = [[UIImageView alloc] initWithFrame:CGRectMake(btnSize.width + 95, 5, btnSize.width, btnSize.height)];
    finishBtnImg.image = [UIImage imageNamed:@"siftSideBar/btn_blue"];
    UILabel *finishLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, labelSize.width, labelSize.height)];
    finishLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:15.0];
    finishLabel.textColor = [Common colorWithRGB:0xffffff];
    finishLabel.text = @"完 成";
    finishLabel.textAlignment = UITextAlignmentCenter;
    [finishBtnImg addSubview:finishLabel];
    UITapGestureRecognizer *onTapFinishBtn = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(finishBtn:)];
    finishBtnImg.userInteractionEnabled = YES;
    [finishBtnImg addGestureRecognizer:onTapFinishBtn];
    
    [cell.contentView addSubview:deleteBtnImg];
    [cell.contentView addSubview:finishBtnImg];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return 6;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    switch (indexPath.row) {
        case 0:
            return TITLE_CELL_HEIGHT;
            break;
        case 1:
            return GO_TO_WHERE;
            break;
        case 2:
            return WHO_CELL_HEIGHT;
            break;
        case 3:
            return HOW_FAR_CELL_HEIGHT;
            break;
        case 4:
            return KM_SELECT_CELL_HEIGHT;
            break;
        case 5:
            return HOW_FAR_CELL_HEIGHT;
            break;
        default:
            return 0;
            break;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = nil;
    switch (indexPath.row) {
        case 0:
            cell = [tableView dequeueReusableCellWithIdentifier:@"TitleCell"];
            // Configure the cell...
            if(cell == nil)
            {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TitleCell"];
            }
            UIImageView *close = [[UIImageView alloc] initWithFrame:CGRectMake(280, 10, 20, 20)];
            close.image = [UIImage imageNamed:@"siftSideBar/X"];
            UITapGestureRecognizer *onTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeSideBar:)];
            close.userInteractionEnabled = YES;
            UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(15, TITLE_CELL_HEIGHT - 0.5, self.view.bounds.size.width - 30, 0.5)];
            lineView.backgroundColor = [Common colorWithRGB:0xb2b2b2];
            [close addGestureRecognizer:onTap];
            [cell.contentView addSubview:close];
            [cell.contentView addSubview:lineView];
            break;
        case 1:
            cell = [tableView dequeueReusableCellWithIdentifier:@"WhoCell"];
            // Configure the cell...
            if(cell == nil)
            {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"WhoCell"];
            }
            else
            {
                while ([cell.contentView.subviews lastObject] != nil) {
                    [(UIView*)[cell.contentView.subviews lastObject] removeFromSuperview];  //删除并进行重新分配
                }
            }
            [self whoCellSetup:cell];
            break;
        case 2:
            cell = [tableView dequeueReusableCellWithIdentifier:@"WithWhoCell"];
            // Configure the cell...
            if(cell == nil)
            {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"WithWhoCell"];
            }
            else
            {
                while ([cell.contentView.subviews lastObject] != nil) {
                    [(UIView*)[cell.contentView.subviews lastObject] removeFromSuperview];  //删除并进行重新分配
                }
            }
            [self withWhoCellSetup:cell];
            break;
        case 3:
            cell = [tableView dequeueReusableCellWithIdentifier:@"HowFarCell"];
            // Configure the cell...
            if(cell == nil)
            {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HowFarCell"];
            }
            else
            {
                while ([cell.contentView.subviews lastObject] != nil) {
                    [(UIView*)[cell.contentView.subviews lastObject] removeFromSuperview];  //删除并进行重新分配
                }
            }
            [self howFarCellSetup:cell];
            break;
        case 4:
            cell = [tableView dequeueReusableCellWithIdentifier:@"SlideCell"];
            // Configure the cell...
            if(cell == nil)
            {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SlideCell"];
            }
            else
            {
                while ([cell.contentView.subviews lastObject] != nil) {
                    [(UIView*)[cell.contentView.subviews lastObject] removeFromSuperview];  //删除并进行重新分配
                }
            }
            [self slideCellSetup:cell];
            break;
        case 5:
            cell = [tableView dequeueReusableCellWithIdentifier:@"ButtonCell"];
            // Configure the cell...
            if(cell == nil)
            {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ButtonCell"];
            }
            else
            {
                while ([cell.contentView.subviews lastObject] != nil) {
                    [(UIView*)[cell.contentView.subviews lastObject] removeFromSuperview];  //删除并进行重新分配
                }
            }
            [self buttonCellSetup:cell];
            break;
        default:
            break;
    }
    
    // Configure the cell...
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

#pragma mark - UIGestureRecognizer
-(void)chooseWho:(UIGestureRecognizer*)onTap
{
    NSLog(@"=====>newsideBarViewController====>chooseWho %@",onTap);
    UIImageView *img = (UIImageView*)[onTap.view viewWithTag:10001];
    BOOL state = [self changeChoose:img];
    NSLog(@"================================> %@",img.accessibilityIdentifier);
    if (state) {
        if ([img.accessibilityIdentifier isEqualToString:@"文化"] || [img.accessibilityIdentifier isEqualToString:@"温泉"] || [img.accessibilityIdentifier isEqualToString:@"乡村"] || [img.accessibilityIdentifier isEqualToString:@"电影"]) {
            [self.typesSelected addObject:img.accessibilityIdentifier];
        } else {
            [self.tagsSelected addObject:img.accessibilityIdentifier];
        }
    } else {
        if ([img.accessibilityIdentifier isEqualToString:@"文化"] || [img.accessibilityIdentifier isEqualToString:@"温泉"] || [img.accessibilityIdentifier isEqualToString:@"乡村"] || [img.accessibilityIdentifier isEqualToString:@"电影"]) {
            [self.typesSelected removeObject:img.accessibilityIdentifier];
        } else {
            [self.tagsSelected removeObject:img.accessibilityIdentifier];
        }
    }
}

-(void)chooseWithWho:(UIGestureRecognizer*)onTap
{
    NSLog(@"=====>newsideBarViewController====>chooseWithWho %@",onTap);
    UIImageView *img = (UIImageView*)[onTap.view viewWithTag:20001];
    BOOL state = [self changeChoose:img];
    NSLog(@"================================> %@",img.accessibilityIdentifier);
    if (state) {
        [self.typesSelected addObject:img.accessibilityIdentifier];
    } else {
        [self.typesSelected removeObject:img.accessibilityIdentifier];
    }
}

-(void)chooseWhere:(UIGestureRecognizer*)onTap
{
    NSLog(@"=====>newsideBarViewController====>chooseWhere %@",onTap);
    UIImageView *img = (UIImageView*)[onTap.view viewWithTag:30001];
    UILabel *lab = (UILabel*)[onTap.view viewWithTag:30002];
    BOOL state = [self changeChoose:img];
    NSLog(@"================================> %@",img.accessibilityIdentifier);
    if (state) {
        lab.textColor = [UIColor blackColor];
        [self.areasSelected removeObject:img.accessibilityIdentifier];
    } else {
        lab.textColor = [UIColor whiteColor];
        [self.areasSelected addObject:img.accessibilityIdentifier];
    }
}

-(void)chooseDistance:(UIGestureRecognizer*)onTap
{
    NSLog(@"=====>newsideBarViewController====>chooseDistance %ld",(long)onTap.view.tag);
    self.slider.value = 0;
    NSArray *sliderDot = [NSArray arrayWithObjects:@"20", @"78", @"136", @"194", @"252", nil];
    self.distance = onTap.view.accessibilityIdentifier;
    if ([onTap.view.accessibilityIdentifier isEqualToString:@"全部"]) {
        self.distance = @"5000000";
    }
    self.slider.value = onTap.view.frame.origin.x;
    int tapView = (int)onTap.view.tag - 40000;
    for (int i = 0; i < 5; i++) {
        NSString *dot = [sliderDot objectAtIndex:i];
        int tag = 40000 + [dot intValue];
        UIView *view = (UIView*)[self.cell viewWithTag:tag];
        UIImageView *img = (UIImageView*)[view viewWithTag:40001];
        UILabel *lab = (UILabel*)[view viewWithTag:40002];
        if ([dot intValue] <= tapView) {
            img.image = [UIImage imageNamed:@"siftSideBar/dot_blue"];
            lab.textColor = [Common colorWithRGB:0x18aaf6];
        } else {
            img.image = [UIImage imageNamed:@"siftSideBar/dot_grey"];
            lab.textColor = [Common colorWithRGB:0x4c4c4c];
        }
    }
}

-(void)deleteBtn:(UIGestureRecognizer*)onTap
{
    NSLog(@"=====>newsideBarViewController====>deleteBtn %@",onTap);
    [self.tagsSelected removeAllObjects];
    [self.typesSelected removeAllObjects];
    self.distance = nil;
    [_tableView reloadData];
}

-(void)finishBtn:(UIGestureRecognizer*)onTap
{
    NSLog(@"=====>newsideBarViewController====>finishBtn %@",onTap);
    [[TransforController sharedInstanceOfSpecialMessageViewController] refreshSiftCell:_tagsSelected typeList:_typesSelected distance:_distance areasSelected:_areasSelected];
    NSLog(@"=====>%s======>typeSelected %@",__FUNCTION__, _tagsSelected);
    [self dismissViewControllerAnimated:YES completion:nil];
}

-(void)closeSideBar:(UIGestureRecognizer*)onTap
{
    NSLog(@"=====>newsideBarViewController====>closeSideBar %@",onTap);
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - private
-(BOOL)changeChoose:(UIImageView*)img
{
    NSString *imgName = img.accessibilityValue;
    NSArray *imgNameArray = [imgName componentsSeparatedByString:@"_in"];
    NSString *newImgName = nil;
    BOOL state = NO;
    if ([imgNameArray count] == 1) {
        newImgName = [NSString stringWithFormat:@"%@%@",imgName,@"_in"];
        state = YES;
    } else if ([imgNameArray count] == 2) {
        imgNameArray = [imgName componentsSeparatedByString:@"_in"];
        newImgName = imgNameArray[0];
        state = NO;
    }
    [img setAccessibilityValue:newImgName];
    img.image = [UIImage imageNamed:newImgName];
    return state;
}

-(BOOL)changeWhereChoose:(UIView*)view
{
    UIImageView *img = (UIImageView*)[view viewWithTag:30001];
    BOOL state = [self changeChoose:img];
    UILabel *nameLabel = (UILabel*)[view viewWithTag:30002];
    if (!state) {
        nameLabel.textColor = [UIColor whiteColor];
    } else {
        nameLabel.textColor = [Common colorWithRGB:0x4c4c4c];
    }
    return state;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"Customize"];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"Customize"];
}

@end
